//
//  LightingControl.m
//  iPhoneControlApplication
//
//  Created by Elliot Chapple on 11/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "LightingControl.h"


@implementation LightingControl

//synthesize all aspects from the header file
@synthesize dhallLight;
@synthesize dlivingRoomLight;
@synthesize dkitchenLight;
@synthesize	dbathroomOneLight;
@synthesize ubathroomTwoLight;
@synthesize ubedroomOneLight;
@synthesize ubedroomTwoLight;
//@synthesize ustudyLight;
//Master control synth
@synthesize masterControlSwitch;
@synthesize switchToMasterControls;


//Set up the method to show when Master switch is changed all lights go off.

-(IBAction)masterSwitchChanged:(id)sender
{
	UISwitch *masterSwitch = (UISwitch *)sender;
	BOOL setting = masterSwitch.isOn;
	[dhallLight			setOn:setting animated:YES];
	[dlivingRoomLight	setOn:setting animated:YES];
	[dkitchenLight		setOn:setting animated:YES];
	[dbathroomOneLight	setOn:setting animated:YES];
	[ubathroomTwoLight	setOn:setting animated:YES];
	[ubedroomOneLight	setOn:setting animated:YES];
	[ubedroomTwoLight	setOn:setting animated:YES];
	//[ustudyLight		setOn:setting animated:YES];
}


//Toggle the Show/Hide for the Master Control Sets

-(IBAction)toggleMasterControlSet:(id)sender
{
	//Link to Segmented Control in Interface Builder
	UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
	NSInteger segment = segmentedControl.selectedSegmentIndex;
	
	//Create if statement to see if controls are visible or not using the kShowMasterControls
	//variable defined within the header file
	if (segment == kShowMasterControls) [switchToMasterControls setHidden:NO];
	else [switchToMasterControls setHidden:YES];
}




/* Standard Code from Apple Inc - Defaults left to preserve integrity
 
 
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	//User notification to show which device control is being simulated.
	NSString *newText = [[NSString alloc] initWithFormat:@"This application is now simulating control of Lighting within the home"];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Established" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[newText release];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

//Memory Management
- (void)dealloc {
    [super dealloc];
}


@end
